local skel = fk.CreateSkill {
  name = "emo__langce",
}

Fk:loadTranslationTable{
  ["emo__langce"] = "狼策",
  [":emo__langce"] = "每当你受到伤害后，你可以获得随机两张锦囊牌（可能来自未开启卡包！），然后可使用其中一张，若使用了<font color='red'>♥</font>牌，你回复1点体力。",

  ["#emo__langce-use"] = "狼策：你可以使用其中一张牌，若使用<font color='red'>♥</font>牌回复1点体力",
}

skel:addEffect(fk.Damaged, {
  anim_type = "masochism",
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = table.filter(table.connect(room.draw_pile, room.discard_pile), function (id)
      return Fk:getCardById(id).type == Card.TypeTrick
    end)
    table.insertTable(cards, table.filter(room.void, function (id)
      return Fk:getCardById(id):getMark(skel.name) ~= 0
    end))
    -- 打印额外牌的信息
    local extraInfo = room:getTag("emo__langce_extra")
    if extraInfo == nil then
      -- 文和乱武，用间，忠胆，应变，国战，图国，玩点
      local exPackName = {"chaos_mode_cards", "espionage_cards", "vanished_dragon_cards", "variation_cards", "hegemony_cards",
      "tuguo_cards", "wd_xushi_cards", "moepack_cards", "moepack_cardex"}
      local exCardName = {"raid_and_frontal_attack", "ty__drowning", "underhanding", "enemy_at_the_gates", "demobilized",
      "honey_trap", "daggar_in_smile", "shangyang_reform"}
      extraInfo = {}
      for _, card in ipairs(Fk.cards) do
        if card.type == Card.TypeTrick and table.contains(Fk:currentRoom().disabled_packs, card.package.name) then
          if table.contains(exCardName, card.name) or (table.contains(exPackName, card.package.name) and not card.is_derived) then
            table.insert(extraInfo, {card.name, card.suit < 5 and card.suit or math.random(4),
            (card.number > 0 and card.number < 14) and card.number or math.random(13)})
          end
        end
      end
      room:setTag("emo__langce_extra", extraInfo)
    end
    local get = {}
    for _ = 1, 2 do
      if #cards == 0 or math.random() < 0.4 then -- 打印
        if #extraInfo > 0 then
          local info = table.random(extraInfo)
          local card = room:printCard(info[1], info[2], info[3])
          room:setCardMark(card, MarkEnum.DestructIntoDiscard, 1)
          room:setCardMark(card, skel.name, 1)
          table.insert(get, card.id)
        end
      else
        table.insert(get, table.remove(cards, math.random(#cards)))
      end
    end
    room:obtainCard(player, get, false, fk.ReasonJustMove, player, skel.name)
    get = table.filter(get, function (id) return table.contains(player:getCardIds("h"), id) end)
    if #get == 0 then return end
    local use = room:askToUseRealCard(player, {
      pattern = get, skill_name = skel.name, skip = false, prompt = "#emo__langce-use",
    })
    if use and use.card.suit == Card.Heart and not player.dead then
      room:recover { num = 1, skillName = skel.name, who = player, recoverBy = player }
    end
  end,
})

return skel
